<template>
  <div class="mine-body">
    <van-popup v-model="show" name="logout" class="exit-box">
      <p>确定退出登录？</p>
      <div class="exit-button">
        <span @click="handleCancelClick">取消</span>
        <span @click="handleExitClick">确定</span>
      </div>
    </van-popup>
    <van-popup
      v-model="languageShow"
      name="language-change"
      class="language-box"
    >
      <p :style="selectedLanguage('zh')" @click="handleLanguage('zh')">
        简体中文
      </p>
      <p :style="selectedLanguage('zhTw')" @click="handleLanguage('zhTw')">
        繁体中文
      </p>
      <p :style="selectedLanguage('en')" @click="handleLanguage('en')">
        English
      </p>
    </van-popup>

    <img :src="divImg" class="top-background" alt="" />
    <div class="header" v-if="isLogin" @click="handleDetail">
      <img :src="avata" alt="" />
      <div class="login-tip">
        <span>{{ user.nickname }}</span>
        <span>{{ user.id }}</span>
      </div>
    </div>
    <div class="header" @click="handleLogin" v-else>
      <img :src="avata" alt="" />
      <div class="login-tip">
        <span>点击登录</span>
        <span>登录后享受更多个性服务</span>
      </div>
    </div>
    <div class="mine-list">
      <div v-if="isLogin" @click="handleAuth" >
        <van-icon name="user-circle-o" class="icon" />
        <span>实名认证</span>
        <van-icon name="arrow" class="icon right" />
      </div>
      <div @click="handleFaq">
        <van-icon name="question-o" class="icon" />
        <span>常见问题</span>
        <van-icon name="arrow" class="icon right" />
      </div>
      <div>
        <van-icon name="info-o" class="icon" />
        <span>关于我们</span>
        <van-icon name="arrow" class="icon right" />
      </div>
      <div>
        <van-icon name="cluster-o" class="icon" />
        <span>版本信息</span>
        <van-icon name="arrow" class="icon right" />
      </div>
      <van-cell name="language" is-link @click="handleLanguageChange">
        <van-icon name="exchange" class="icon" />
        <span>语言切换</span>
        <van-icon name="arrow" class="icon right" />
      </van-cell>
      <van-cell v-if="isLogin" name="exit" is-link @click="handleClickExit">
        <van-icon name="close" class="icon" />
        <span>退出登录</span>
        <van-icon name="arrow" class="icon right" />
      </van-cell>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "mine",
  computed: {
    ...mapState("user", ["isLogin"]),
    user() {
      const user = this.$store.state.user;
      console.log('user', user);
      return user;
    },
  },
  data() {
    return {
      // divImg: "background:" + require("../assets/top.png"),
      divImg: require("../assets/top.png"),
      avata: require("../assets/avata.png"),
      language: "zh",
      show: false,
      languageShow: false,
    };
  },
  methods: {
    handleClickExit() {
      this.show = true;
    },
    handleCancelClick() {
      this.show = false;
    },
    handleExitClick() {
      // this.isLogin = false
      // this.show = false
      this.$store.dispatch("user/logout");
      this.show = false
    },
    handleAuth() {
      this.$router.push('/person')
    },
    handleLogin() {
      this.$router.push("/login");
    },
    handleDetail() {
      this.$router.push("/user/mine");
    },
    handleFaq() {
      this.$router.push("/faq");
    },
    handleFocus(index) {
      this.focus = index;
    },
    handleLanguageChange() {
      this.languageShow = true;
    },
    selectedLanguage(val) {
      if (val === this.language) {
        return "color: #3068F4";
      } else {
        return "";
      }
    },
    handleLanguage(val) {
      this.language = val;
      this.languageShow = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.mine-body {
  display: flex;
  flex-direction: column;

  background-repeat: no-repeat;
  .top-background {
    height: 105px;
    width: 100%;
    // position: absolute;
    z-index: 0;
  }
  .header {
    display: flex;
    flex-direction: row;
    margin-top: 50px;
    position: absolute;
    padding: 20px;
    z-index: 10;
    img {
      width: 73px;
      height: 73px;
      box-shadow: 0px 14px 46px 0px rgba(105, 106, 108, 0.08);
      border-radius: 50%;
    }
    .login-tip {
      display: flex;
      flex-direction: column;
      text-align: start;
      justify-content: space-around;
      margin-left: 20px;
      span:first-child {
        font-size: 18px;
        font-weight: bold;
        font-family: PingFang TC;
        color: #333333;
        line-height: 23px;
      }
      span:nth-child(2) {
        font-size: 12px;
        font-family: PingFang TC;
        color: #999999;
        line-height: 23px;
      }
    }
  }
  .mine-list {
    display: flex;
    flex-direction: column;
    margin-top: 60px;
    div {
      display: flex;
      flex-direction: row;
      height: 60px;
      border-bottom: #eee solid 1px;
      align-items: center;
      padding: 0 20px;
      .icon {
        font-size: 20px;
        color: #393939;
      }
      .right {
        color: #c9c9c9;
      }
      span {
        margin-left: 19px;
        font-size: 16px;
        color: #333333;
        flex: 1;
        text-align: left;
        line-height: 25px;
      }
    }
    van-cell {
      @extend div;
    }
    div:last-child {
      border-bottom: none;
    }
  }
  .exit-box {
    width: 270px;
    background: #ffffff;
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    flex-direction: column;
    p {
      width: 100%;
      padding: 20px 0;
      font-size: 17px;
      color: #333;
      line-height: 25px;
      font-weight: bold;
    }
    .exit-button {
      display: flex;
      flex-direction: row;
      flex: 1;
      width: 100%;
      justify-content: space-around;
      span {
        display: flex;
        flex: 1;
        height: 100%;
        align-items: center;
        border-top: solid 1px #666;
        justify-content: center;
        color: #3068f4;
        font-size: 16px;
        font-weight: bold;
        padding: 20px 0;
      }
      span:nth-child(2) {
        border-left: solid 1px #333;
      }
    }
  }
  .language-box {
    width: 320px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    padding: 10px 0;
    p {
      height: 30px;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 10px 0;
      font-size: 16px;
      color: #333;
    }
  }
}
</style>
